<template>
  <div id="app">
    <template v-if="route.path.startsWith('/user')">
      <router-view />
    </template>
    <template v-else>
      <BasicLayout />
      <div v-show="isHidden"><chat-box-com /></div>
    </template>
  </div>
</template>

<style>
.hidden {
  display: none;
}
#app {
}
body {
  margin: 0;
  width: 100%;
}

html {
  width: 100%;
  height: 100%;
}

.app {
  width: 100%;
  height: 100%;
}
</style>
<script setup lang="ts">
import BasicLayout from "@/layouts/BasicLayout";
import { onMounted, ref } from "vue";
import { useRoute } from "vue-router";
import ChatBoxCom from "@/components/ChatBoxCom.vue";

const route = useRoute();
const isHidden = ref(false);


/**
 * 全局初始化函数，有全局单次调用的代码，都可以写到这里
 */
const doInit = () => {
  console.log("hello 欢迎来到我的项目");
  console.log("create");
  /* eslint-disable */
  // @ts-ignore
  window.L2Dwidget
    //此处是对点击人物时触发事件的监听
    .on('*', (name:any) => {
      console.log('%c 你点击了 ' + '%c -> ' + name, 'background: #222; color: yellow',
        'background: #fff; color: #000')
    })
    //对人物的属性配置
    .init({
      pluginRootPath: '../live2dw/', //人物文件夹的位置
      pluginJsPath: 'lib/',
      pluginModelPath: 'live2d-widget-model-z16/assets/',
      model: {
        jsonPath: '../live2dw/live2d-widget-model-z16/assets/z16.model.json'
      },
      dialog: {
        enable: true, //是否开启对话框
        script: {
          //触摸到身体
          'tap body': '害羞⁄(⁄ ⁄•⁄ω⁄•⁄ ⁄)⁄',
          //触摸到头部
          'tap face': '~~'
        }
      },
      display: { //人物的属性配置
        position: 'left',
        width: 150,
        height: 343,
        hOffset: 1300, // 横向偏移
        vOffset: 30 // 纵向偏移
      },
      mobile: {
        show: true, //是否在移动端展示
        scale: 0.5 //t透明度
      }

    });
};

const handleMouseClick = (event:any) => {
  console.log("点击页面");
  let mouseX = event.clientX;
  let mouseY = event.clientY;
  console.log(mouseX, mouseY);
  if (mouseX > 1340 && mouseX < 1415 && mouseY > 390 && mouseY < 600) {
    //isChatDisplay.value = !isChatDisplay.value;
    isHidden.value = !isHidden.value;
    return;
  }
};


onMounted(() => {
  console.log('点击页面');
  document.addEventListener("click", handleMouseClick);
  doInit();
});

//创建
const create = () => {
};




</script>
